#!/bin/bash

curr_dir=$(pwd)

target_dir="$HOME/clash"
if [ ! -d $target_dir ]; then
	echo "mkdir $target_dir"
	cp -r ./clash $target_dir
fi

tmp_pid=$(ps | grep clash | awk '{print $1}')
if [ ! $tmp_pid = "" ]; then
	echo "kill `clash`"
	kill -TERM ${tmp_pid}
fi

echo "cd $target_dir"
cd $target_dir
chmod +x .

nohup ./clash -d . 1>./log 2>/dev/null &

echo "cd $curr_dir"
cd $curr_dir
